<template>
  <div class="lottery">
    <el-dialog title="摇号结果" :visible.sync="lotteryShow" size="small" top="10%">
      <el-form v-bind="getFormProps()" v-if="lotteryType==='lotteryhistory'">
        <el-radio-group v-model="lotteryTab" class="checker-tab" @change="handleStatusChange">
          <el-radio :label="item" v-for="(item,index) in tabList" :key="index" v-if="index <= race_detail.currentLottery">第{{item}}轮</el-radio>
        </el-radio-group>
      </el-form>
      <div class="managebox">
        <el-table :data="race_lottery_list.list" v-if="race_lottery_list.total > 0" v-bind="getTableProps()">
          </el-table-column>
          <el-table-column label="用户" width="360">
            <template slot-scope="scope">
              <e-avatar class="logo" :src="scope.row.iconUrl"/>
              <span class="team-name" :title="scope.row.commingName">{{ scope.row.commingName }}</span>
              <img class="sub-logo" :src="scope.row.pcImgtxtUrl" v-show="scope.row.pcImgtxtUrl">
            </template>
          </el-table-column>
          <el-table-column label="性别" width="120">
            <template slot-scope="scope">
              <span class="player-info" v-if="scope.row.sex === 1">男</span>
              <span class="player-info" v-else>女</span>
            </template>
          </el-table-column>
          <el-table-column label="组别" prop="groupTypeName" width="130"></el-table-column>
          <el-table-column label="所在地" prop="address" :show-overflow-tooltip="true"></el-table-column>
        </el-table>

        <!--无数据提示-->
        <div class="no_matchlist" v-else-if="race_lottery_list.total == 0">
          <p><img src="/static/images/match/nomatch.png" alt=""></p>
          <p>暂无数据</p>
        </div>
        <!--loading-->
        <div class="loading" v-else><div v-loading.body="true"></div></div>
        <!--分页-->
        <el-pagination
          v-bind="getPaginationProps(race_lottery_list)"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange">
        </el-pagination>

        <div class="button-box" v-if="race_lottery_list.total > 0">
          <el-button type="primary" v-if="lotteryType === 'lottery'" @click="exportExcel(race_detail.currentLottery)">导出Excel</el-button>
          <el-button type="primary" v-else @click="exportExcel(lotteryTab)">导出Excel</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { pagingList } from 'utils/mixins'
  import { downloadFile } from 'utils'
  export default {
    mixins: [pagingList],
    props: {
      islottery: {
        type: Boolean,
        default: false
      },
      history: {
        type: Boolean,
        default: false
      },
      lotteryType: String
    },
    created () {
      let i = 1
      while (i < 50) {
        this.tabList.push(i)
        i++
      }
    },
    computed: {
      ...mapGetters({
        race_detail: 'race_detail',
        race_lottery_list: 'race_lottery_list'
      })
    },
    data () {
      return {
        dialogVisible: false,
        query: this.getQuery(),
        lotteryTab: 1,
        lotteryShow: this.islottery,
        tabList: []
      }
    },
    watch: {
      islottery: function (val) {
        this.lotteryShow = val
        if (this.lotteryShow && this.lotteryType === 'lottery') { // 当次摇号
          this.lotteryList(this.race_detail.currentLottery + 1)
        } else { // 摇号历史
          this.lotteryList(this.lotteryTab)
        }
      },
      lotteryShow: function (val) {
        this.$emit('lotteryChange', val)
      }
    },
    methods: {
      handleStatusChange (value) {
        this.lotteryList(value)
      },
      lotteryList (num) {
        this.query.lun = num
        this.query.isYaoHaoHis = true
        delete this.query.status
        delete this.query.groupType
        this.$store.dispatch('race_lottery_list', this.query)
      },
      // 导出
      exportExcel (value) {
        let fileName = this.race_detail.matchName + '第' + value + '轮摇号.xls'
        let url = '/api/match/sign/export/tresult?matchId=' + this.$route.query.id + '&lun=' + value
        downloadFile(url, fileName)
      }
    }
  }
</script>

<style lang="scss">
.loading{
  div{
    min-height: 200px;
  }
  min-height: 200px;
}
.no_matchlist{
  text-align: center;
  color:#999;
}
.lottery{
  .checker-tab.el-radio-group{
    margin: 0;
  }
  .el-dialog__body{
    padding-bottom: 35px;
  }
  .el-dialog--small{
    min-width: 900px;
  }
  .logo {
    width: 38px;
    height: 38px;
    margin: 11px 10px 0 0;
    border-radius: 50%;
  }
  .reset {
    margin-right: 10px;
  }
  .sub-logo {
    height: 14px;
    margin: 23px 0 0 5px;
  }
  .team-name {
    line-height: 60px;
    height: 60px;
    max-width:205px;
    overflow: hidden;
    text-overflow:ellipsis;
  }
  .team-name,
  .logo,
  .sub-logo,
  .checkbox {
    float: left;
  }

  .pagination {
    display: inline-block;
  }

  .page {
    margin: 40px auto;
  }
}
</style>
